package com.sohu.sip.auth.dao.hibernate;

import java.util.List;

import com.sohu.peak.gallery.dao.hibernate.BaseHibernateDAO;
import com.sohu.peak.util.HibernateHelper;
import com.sohu.peak.util.Logger;
import com.sohu.peak.util.Pagination;
import com.sohu.sip.auth.dao.OpenServiceDao;
import com.sohu.sip.auth.po.OpenService;

public class OpenServiceDaoImpl extends BaseHibernateDAO implements
		OpenServiceDao {
	private static final Logger log = new Logger();
	public void del(OpenService os) {
		try {
			getSession().delete(os);
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public OpenService getOpenService(Long id) {
		try {
			OpenService os = (OpenService) getSession().get(OpenService.class, id);
			return os;
		} catch (Exception e) {
			log.error(e.getMessage());
			return null;
		}
	}

	public OpenService getOpenService(String validateCode) {
		try {
			String queryString = "from OpenService where validateCode =?";
			OpenService os = (OpenService) HibernateHelper.getUniqueResult(getSession(), queryString, new String[] { validateCode });
			return os;
		} catch (Exception e) {
			log.error(e.getMessage());
			return null;
		}
	}

	public List<OpenService> getOpenServiceList(String queryString, Pagination pagination, Object[] params) {
		List osList = null;
		try {
			osList = (List) HibernateHelper.pageQuery(getSession(),
					getSession().createQuery(queryString), pagination, params);
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return osList;
	}

	public OpenService merge(OpenService os) {
		try {
			OpenService result = (OpenService) getSession().merge(os);
			return result;
		} catch (RuntimeException re) {
			throw re;
		}
	}

	public void save(OpenService os) {
		try {
			getSession().save(os);
		} catch (Exception re) {
			re.printStackTrace();
		}
	}

}
